package com.mzy.datepackage.M2022.May.sevent;

import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author mzy
 * @Date 2022/5/7 16:20
 * @Version 1.0
 */
public class Demo {
    public static void main(String[] args) throws IOException, InterruptedException {

        Process p =Runtime.getRuntime().exec("ipconfig /all");

        boolean res = p.waitFor(5, TimeUnit.SECONDS);
        if(!res) {
            System.out.println("Time out");
        }
        InputStream inputStream = p.getInputStream();
        byte[] data = new byte[1024];
        String result = "";
        while(inputStream.read(data) != -1) {
            result += new String(data,"GBK");
        }
        if (result == "") {
            InputStream errorStream = p.getErrorStream();
            while(errorStream.read(data) != -1) {
                result += new String(data,"GBK");
            }
        }
        p.destroy();
        System.out.println(result);
    }
}
